﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FileNameConverter
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        public Form1 MainFrom;
        private void Form2_Load(object sender, EventArgs e)
        {
            //From2開始先調為false，防止使用者直接關閉視窗
            MainFrom.ActionComplited = false; 
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bool isOK = true;
            uint Minimum = 0 , Maxmum = 0;
            try
            {
                Minimum = Convert.ToUInt32(textBox1.Text);
                Maxmum = Convert.ToUInt32(textBox2.Text);
            }
            catch (Exception ex)
            {
                isOK = false;
                MessageBox.Show(ex.Message);
            }
            if (isOK)
            {
                if (Minimum > Maxmum)
                {
                    isOK = false;
                    MessageBox.Show("輸入頁碼需從小到大。(例如︰ 1 - 100)");
                }
                else if (Minimum % 2 != Maxmum % 2)
                {
                    isOK = false;
                    MessageBox.Show("請確認頁碼範圍");
                }
            }
            if (isOK)
            {
                MainFrom.MinimumPage = Convert.ToUInt32(textBox1.Text);
                MainFrom.MaxmumPage = Convert.ToUInt32(textBox2.Text);
                if (radioButton1.Checked)
                    MainFrom.IsFromHead = true;
                else
                    MainFrom.IsFromHead = false;
                MainFrom.ActionComplited = true;
                this.Close();
            }
        }
    }
}
